package com.ruoyi.translate.service.impl;

import java.util.List;

import javax.annotation.Resource;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.pay.manager.domain.PayManager;
import com.ruoyi.pay.manager.service.IPayManagerService;
import com.ruoyi.recharge.domain.Recharge;
import com.ruoyi.recharge.service.IRechargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.translate.mapper.TranslateMapper;
import com.ruoyi.translate.domain.Translate;
import com.ruoyi.translate.service.ITranslateService;
import com.basic.service.impl.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * 发票Service业务层处理
 *
 * @author ruoyi
 * @date 2024-01-18
 */
@Service
public class TranslateServiceImpl extends BaseServiceImpl<Long, Translate> implements ITranslateService
{

//    @Autowired
//    private IPayManagerService managerService;
//    @Autowired
//    private IRechargeService chargeService;

//    @Resource
//    public void setChargeService(IRechargeService chargeService) {
//		this.chargeService = chargeService;
//	}
	public TranslateServiceImpl(TranslateMapper baseMapper) {
		super(baseMapper);
		// TODO Auto-generated constructor stub
	}
    /**
     * 查询发票
     *
     * @param id 发票主键
     * @return 发票
     */
    @Override
    public Translate selectById(Integer id)
    {
        return baseMapper.selectById(id);
    }

    /**
     * 查询发票列表
     *
     * @param translate 发票
     * @return 发票
     */
    @Override
    public List<Translate> selectList(Translate translate)
    {
        return baseMapper.selectList(translate);
    }

    /**
     * 新增发票
     *
     * @param translate 发票
     * @return 结果
     */
    @Override
    public int insert(Translate translate)
    {
//        translate.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insert(translate);
    }

    /**
     * 修改发票
     *
     * @param translate 发票
     * @return 结果
     */
    @Override
    @Transactional
    public int update(Translate translate)
    {
//        if (translate.getAuditStatus() == 1) {
//        Translate dataSource = selectById(translate.getId().intValue());
//        if (0 == dataSource.getType()) {
//
//            Recharge selectById = chargeService.selectById(dataSource.getAssocId());
//            Recharge charge = new Recharge();
//
//            charge.setId(selectById.getId());
//            if (translate.getAuditStatus() == 1) {
//                charge.setTranslate((byte) 3);
//            } else if (translate.getAuditStatus() == 2) {
//                charge.setTranslate((byte) 2);
//            }
//            chargeService.update(charge);
//
//        } else if (1 ==  dataSource.getType()) {
//
//            PayManager selectById = managerService.selectById(dataSource.getAssocId());
//
//            PayManager manager = new PayManager();
//            manager.setId(selectById.getId());
//            if (translate.getAuditStatus() == 1) {
//                manager.setTranslate((byte) 3);
//            } else if (translate.getAuditStatus() == 2) {
//                manager.setTranslate((byte) 2);
//            }
//            managerService.update(manager);
//        }
//        }
//        translate.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.update(translate);
    }
    /**
     * 批量删除发票
     *
     * @param ids 需要删除的发票主键
     * @return 结果
     */
    @Override
    public int deleteByIds(Integer[] ids)
    {
        return baseMapper.deleteByIds(ids);
    }

    /**
     * 删除发票信息
     *
     * @param id 发票主键
     * @return 结果
     */
    @Override
    public int deleteById(Integer id)
    {
        return baseMapper.deleteById(id);
    }
}
